package com.hmjk.health.util;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class LOCATION_INFO {
	public long upTime = 0;
	public String tid;
	private ArrayList<LOC_DETAIL> list = new ArrayList<LOC_DETAIL>();
	public static final int FLAG_SOS = 0x01;
	
	public static class LOC_DETAIL{
		public double lat;
		public double lng;
		public long time;
		public String addr;
		public int flag;
		
		public LOC_DETAIL(double lat, double lng, String addr, long time, int flag){
			this.lat = lat;
			this.lng = lng;
			this.addr = addr;
			this.time = time;
			this.flag = flag;
		}
	}
	
	
	public LOCATION_INFO(String tid){
		this.tid = tid;
	}
	
	public void insertItem(LOC_DETAIL item){
		list.add(0, item);
	}
	
	public JSONArray createJSONArray(){
		try{
			if(list.size() > 0){
				JSONArray arr = new JSONArray();
				for(LOC_DETAIL d:list){
					JSONObject o = new JSONObject();
					o.put("lat", d.lat);
					o.put("lng", d.lng);
					o.put("addr", d.addr);
					o.put("time", d.time);
					o.put("flag", d.flag);
					//o.put("tid", tid);
					arr.put(o);
				}
				
				return arr;
			}
		}catch(JSONException e){
			e.printStackTrace();
		}
		return null;
	}

	public ArrayList<LOC_DETAIL> getAddrList() {
		// TODO Auto-generated method stub
		return list;
	}
}
